package com.yanqu.road.server.cmd.thief;

import com.yanqu.road.pb.thief.ThiefProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.thief.ThiefModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_THIEF_CATCH, desc = "抓小偷")
public class CatchThiefCmd extends AbstractCommand {

    String thiefUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ThiefProto.CatchThiefReqMsg reqMsg = ThiefProto.CatchThiefReqMsg.parseFrom(packet.getBytes());
        thiefUid = reqMsg.getThiefUid();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ThiefModule.class).catchThief(thiefUid);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ThiefProto.CatchThiefRespMsg.Builder builder = ThiefProto.CatchThiefRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_THIEF_CATCH, builder);
        }
    }
}
